import sys
import time
from decimal import *
sys.path.append("../modules/")
from BayesNetwork import BayesNetwork

BN = BayesNetwork()
BN.parse_encog("./bug/log_ini_structure(problem-shorter).eg")
BN.showProgress = False
BN.showTime = False

#Loading data
variables, data = BN.loadDataset("./bug/alarm_verbose.csv")

# Target structure
target_structure = BN.copy(BN.BayesianNetwork)
BN.generateBNStructureVisualization("target",target_structure)

# Creating initial structure
initial_structure = BN.BayesianNetwork
BN.export_encog("log_ini_structure.eg", initial_structure)
BN.generateBNStructureVisualization("ini_structure", initial_structure)

BN.BayesianNetwork = None

# DEFINE CLASS VARIABLE HERE
class_variable = "BrainTumor"

print "EXPERIMENT 1 -  SEM, Masters search, With MI = 0.5, " + class_variable
st = time.time()
BN.expectationMaximization(variables, data, Decimal('0.01'), initial_structure, None, 10)

#bn_exp1 = BN.structuralExpectationMaximization(variables, data, "final_structure_exp1", Decimal('0.01'), "BBSL", {'class_variable': class_variable, 'classification_threshold': Decimal('0.7'), 'external_edges': True},   initial_structure, Decimal('0.5'), 10)
#print "Total time for experiment: " + str(time.time() - st)
#print "Comparison Data:"
#BN.compareBNStructures(initial_structure, bn_exp1, variables, data, class_variable=class_variable)



#print ""
#print "EXPERIMENT 2 -  SEM, Masters search, no MI , " + class_variable
#st = time.time()
#bn_exp1 = BN.structuralExpectationMaximization(variables, data, "final_structure_exp2", Decimal('0.01'), "BBSL", {'class_variable': class_variable, 'classification_threshold': Decimal('0.7'), 'external_edges': True},   initial_structure, None, 10)
#print "Total time for experiment: " + str(time.time() - st)
#print "Comparison Data:"
#BN.compareBNStructures(initial_structure, bn_exp1, variables, data, class_variable=class_variable)
#
#print ""
#print "EXPERIMENT 3 -  SEM, Masters search, no MI , no external edges, " + class_variable
#st = time.time()
#bn_exp1 = BN.structuralExpectationMaximization(variables, data, "final_structure_exp3", Decimal('0.01'), "BBSL", {'class_variable': class_variable, 'classification_threshold': Decimal('0.7'), 'external_edges': False},   initial_structure, None, 10)
#print "Total time for experiment: " + str(time.time() - st)
#print "Comparison Data:"
#BN.compareBNStructures(initial_structure, bn_exp1, variables, data, class_variable=class_variable)
#
#print ""
#print "EXPERIMENT 4 -  SEM, Masters search, With MI=0.5 , no external edges, " + class_variable
#st = time.time()
#bn_exp1 = BN.structuralExpectationMaximization(variables, data, "final_structure_exp4", Decimal('0.01'), "BBSL", {'class_variable': class_variable, 'classification_threshold': Decimal('0.7'), 'external_edges': False},   initial_structure, Decimal('0.5'), 10)
#print "Total time for experiment: " + str(time.time() - st)
#print "Comparison Data:"
#BN.compareBNStructures(initial_structure, bn_exp1, variables, data, class_variable=class_variable)


